package com.yuaer.demo.springsparkjobhandlerdemo.executor.processor;

import com.yuaer.demo.springsparkjobhandlerdemo.executor.GlobalContext;
import com.yuaer.demo.springsparkjobhandlerdemo.executor.NodeContext;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;

import java.time.LocalDate;

public class RootNodeProcessor implements NodeProcessor{

    @Override
    public Dataset<Row> process(GlobalContext globalContext, NodeContext nodeContext) {
        // 获取SparkSession
        SparkSession sparkSession = globalContext.getSpark();

        // 获取全局参数中的开始日期和结束日期
        LocalDate startDate = (LocalDate) globalContext.getGlobalParams().get("startDate");
        LocalDate endDate = (LocalDate) globalContext.getGlobalParams().get("endDate");

        // 构造查询语句
        String querySql = "select * from table where date between " + startDate + " and " + endDate;

        // 执行查询语句并返回结果
        return sparkSession.sql(querySql);
    }

}
